<template>
	<view class="app-content">
		<!-- 导航 -->
		<view>
			<!-- <u-navbar :is-back="false" :title="title"></u-navbar> -->
			<u-navbar :title="title" :leftIconSize="0" v-if="!loading" :fixed="true" :placeholder="true">
				<view slot="left">
					<view class="u-nav-slot" v-if="daohang.list.length<=0">
						<u-icon @click="tofanhui()" name="arrow-left" size="19" ></u-icon>
						<u-line direction="column" :hairline="false" length="16" margin="0 8px" ></u-line>
						<u-icon @click="toindex()" name="home" size="20" ></u-icon>
					</view>
				</view>
			</u-navbar>
		</view>
		<view class="xiangqing">
			待开发
		</view>
		<u-tabbar v-if="daohang.list.length>0" :zIndex="999" :border="daohang.navi_set.border=='1'?true:false" :value="daohang.naviKey" :activeColor="daohang.navi_set.active_color" :inactiveColor="daohang.navi_set.inactive_color">
			<u-tabbar-item v-for="(item,index) in daohang.list" :badge="item.badge" :key="index" :text="item.text" :icon="daohang.naviKey==index?item.selectedIconPath:item.iconPath" @click="tabClick(item,index)" ></u-tabbar-item>
		</u-tabbar>
		<u-no-network @retry="retry" ></u-no-network>
		<u-toast ref="uToast" />
		<view class="km_loading" v-if="loading">
			<image src="../../static/loading_3.gif" mode=""></image>
		</view>
	</view>
</template>

<script>
	import {
		wappConfig
	} from "@/api/api.js";
	// import {
	// 	getuserinfo,
	// } from "@/api/user.js";
	export default {
		data() {
			return {
				title: 'KMLOVE',
				loading:true,
				config:{},
				pagePath:'/plugin/index/index',
				daohang:{
					list:[],
					naviKey:0,
					navi_set:{
						active_color: "#34C083",
						height: 100,
						inactive_color: "#757575",
					}
				},
			}
		},
		components: {
		},
		onLoad() {
			this.getconfig();
		},
		onShow() {
			if (this.$store.getters.isLogin) {
				console.log(this.$store.getters.isLogin)
				this.getuser();
			}
		},
		methods: {
			retry(){
				this.getconfig();
			},
			tourl(e){
				console.log(e)
				e=decodeURIComponent(e);
				if(!e){
					return true;
				}
				if(e==this.pagePath){
					return true;
				}
				uni.navigateTo({
					url:e,
					fail(error) {
						console.log(error)
						uni.showToast({
							title:"跳转出错",
							icon:"none"
						})
					}
				})
			},
			tofanhui(){
				uni.navigateBack({
					delta: 1,
					fail(){
						 uni.reLaunch({
							 url: '/pages/index/index'
						 });
					}
				})
			},
			toindex(){
				uni.reLaunch({
					url: '/pages/index/index'
				});
			},
			// 切换导航
			tabClick(e,i){
				if(this.daohang.naviKey!=i){
					uni.reLaunch({
						url:e.pagePath,
						fail(err) {
							uni.showModal({
								content:err.errMsg,
								title:"错误提示",
								showCancel:false,
								fail(r) {
									console.log(r)
								}
							})
							console.log(err)
						}
					})
				}
				
			},
			getconfig(){
				let that=this;
				wappConfig({pagePath:that.pagePath}).then(e=>{
					console.log(e)
					that.daohang=e.data.naviList;
					that.loading=false;
				})
				.catch(res => {
					console.log(res)
					uni.showModal({
						content:res.msg?res.msg:"获取配置文件失败",
						title:"提示",
						showCancel:false
					})
					that.loading=false;
				});
			},
			getuser(){
				getuserinfo(this.$store.getters.uid).then(res=>{
					console.log(res)
				}).catch(e=>{
					//TODO handle the exception
					console.log(e)
				})
			},
		}
	}
</script>

<style>
</style>
